package com.dudu.dao;

import java.sql.Connection;
import java.util.List;

import com.dudu.model.PhoneLocation;

import net.sf.json.JSONObject;


import core.CoreDao;
import core.CoreDaoInvoke;
import core.db.DBConnectionUtil;

public class PhoneLocationDao {

	public static void main(String[] args) {

		CoreDao coreDao = new CoreDaoInvoke();
		PhoneLocationDao dao = new PhoneLocationDao();

		PhoneLocation bean = new PhoneLocation();
	}
	
	public PhoneLocation query(CoreDao dao, int phone) {

		Connection con = null;
		PhoneLocation result = null;

		try {
			con = DBConnectionUtil.getDBConnection("emate1");

			StringBuffer sql = new StringBuffer(
					"select id, mobile_number, mobile_area, mobile_type, area_code, post_code, area " +
					"FROM t_mobilephone where mobile_number=?");
			List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(),
					new Object[] { phone });
			if (list != null && list.size() > 0) {
				List<PhoneLocation> items = dao.covertToBean(list, PhoneLocation.class);
				result = items.get(0);
			}

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			DBConnectionUtil.close(null, null, con);
		}
		return result;
	}
}
